package com.lbn.jfqsc;

import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.lbn.baseframe.base.BaseApplication;
import com.lbn.baseframe.utils.L;
import com.lbn.baseframe.utils.SPUtils;
import com.lbn.jfqsc.business.bean.User;

/**
 * @author 李炳南
 * @date 2017/2/28
 */
public class App extends BaseApplication {

    public static User user;
    //1普通用户2社团3商家
    private static App app;
    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        if (SPUtils.contains(this, "USER")) {
            String userJson = (String) SPUtils.get(this, "USER", "");
            L.e("isLogin:"+userJson);
            if (!TextUtils.isEmpty(userJson)) {
                user = new Gson().fromJson(userJson, User.class);
            }
        }
    }

    public static boolean isLogin() {
        return user != null;
    }

    public static User getUser() {
        return user;
    }

    public static void setUser(User user) {
        App.user = user;
    }

    public static void clearUser() {
        user = null;
        SPUtils.remove(app , "USER");
    }

    public static boolean isMerchant() {
        return isLogin() && user.getType() == 3;
    }

    public static boolean isOrganizationUser() {
        return isLogin() && user.getType() == 2;
    }

    public static boolean isCommonUser() {
        return isLogin() && user.getType() == 1;
    }
}
